/**
 * Copyright (C) 2024-2030 Super BilGen & 超亿时代信息技术股份有限公司.All Rights Reserved.
 */
package cn.com.yang.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.junit.Test;

/**
 * @Model cn.com.yang.thread.TestTakGroup
 * @Desc  TODO
 * @author yangyijin
 * @since 2025年4月29日-下午4:39:14
 */
public class TestTaskGroup {
	@SuppressWarnings("unchecked")
	@Test
	public void test() {
		ExecutorService exe = Executors.newFixedThreadPool(10);
		List<Callable<Void>> tasks = new ArrayList();
		for(int i=0;i<10;i++) {
			tasks.add(()->{
				//任务
				int n=0;
				for(int j=0;j<1000000;j++) {
					n+=j;
				}
				System.out.println(n);
				return null;
			});
		}
		try {
			List<Future<Void>> futures = exe.invokeAll(tasks);
		}catch(InterruptedException e) {
			Thread.currentThread().interrupt();
		}
		exe.shutdown();
		System.out.println("所有任务执行完毕");
	}
}
